#!/usr/bin/env python3
from hashlib import sha1
import socket
from random import random
import time
from threading import Thread
from librepeator import init_connect
rand = str( random() )

def rv_proc():
    global sock
    print('thread')
    while True:
        try:
            r = sock.recv(1024)
            if len(r)==0:
                break
            print(r.decode() )
        except Exception as e:
            print(str(e))
            break
            
sock = socket.socket()
sock.connect( ('127.0.0.1',8001) )
# 握手第一步： 发送 SHA1 报文
if init_connect( sock,'uiedd' ):
    #t = Thread(target=rv_proc)
    #t.start()
    print('ok start send')
    for i in range(10):
        time.sleep(1)
        s = '%s : %s\n'%(rand,i)
        sock.send( s.encode('utf8') )
else:
    print('reply error: %s'%reply.decode())
sock.send(''.encode('utf8'))
print('end')
sock.shutdown(socket.SHUT_RDWR)
sock.close()

